<style scoped>
  .weui-form-preview {
    background-color: #fff;
    margin: 5px;
    border-radius: 5px;
  }

  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }

  .rj-cell {
    display: inline-block;
    font-size: 0;
    padding: 5px 15px;
  }

  .rj-cell.max span {
    font-size: 16px;
    padding-right: 20px;
  }

  .rj-cell label {
    color: #333;
    font-size: 14px;
  }

  .rj-cell span {
    padding-left: 5px;
    font-size: 14px;
    color: #333;
  }

  .rj-cell.note {
    width: 100%;
  }

  .rj-cell.note label {
    float: left;
  }

  .rj-cell.note span {
    width: 80%;
    display: inline-block;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .attachimg {
    /*width: 100%;*/
  }

  .tit label, .tit span {
    font-size: 16px;
  }

  .tit label {
    padding-right: 20px;
  }

  .weui-panel.weui-panel_access {
    padding-bottom: 10px;
  }

  .weui-panel__bd:not(.base) {
    width: 98%;
    padding: 0 1% 2px 1%;
  }

  .rj-cont-tit:not(.base) {
    border-radius: 5px;
  }

  .weui-cell {
    background: #fff;
  }

  .weui-cells__title {
    text-align: left;
    background: #eee;
  }

  .oitem {
    padding: 3px;
  }

  #acts span {
    font-size: 14px;
  }

  .weui-label {
    text-align: left;
  }

  .weui-media-box {
    text-align: left;
  }

  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .hd .weui-grid.js_grid {
    font-weight: 600;
  }

  .weui-grid.js_grid {
    width: 25%;
    padding: 10px 1px;
  }

  /*.weui-grid.fir {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.sec {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.thr {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.fou {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.fiv {*/
  /*  width: 15%;*/
  /*}*/
  .weui-grid__label {
    text-overflow: initial;
  }

  /*.view-wrap {*/
  /*  background: #eee;*/
  /*}*/
</style>
<template>
  <div class="comon" style="background: #eee;">
    <div
      style="height: 50px; line-height: 50px; background: #fff; text-align: center; font-size: 16px; border-bottom: 1px solid #bdbbbc; position: relative">
      采收合同详情
      <a href="javascript:" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px"/>
      </a>
    </div>
    <!--    主表信息-->
    <div class="weui-form-preview" style="background: #fff;">
      <div class="weui-form-preview__hd">
        <label class="weui-form-preview__label">编号</label>
        <em class="weui-form-preview__value">{{baseInfo.code}}</em>
      </div>
      <div class="weui-form-preview__bd">
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">名称</label>
          <span class="weui-form-preview__value">{{baseInfo.name}}</span>
        </div>
<!--        <div class="weui-cell">-->
<!--          <div class="weui-cell__hd"><label class="weui-label">采收类型</label></div>-->
<!--          <div class="weui-cell__bd">-->
<!--            <input class="weui-input" readonly  type="text"  name="" :value="baseInfo.harvestType == 2 ? '临采' : '订单户'">-->
<!--          </div>-->
<!--        </div>-->
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">采收主体</label>
          <span class="weui-form-preview__value">{{baseInfo.parta}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">部门</label>
          <span class="weui-form-preview__value">{{baseInfo.departname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">入库库房</label>
          <span class="weui-form-preview__value">{{baseInfo.srname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">质检标准</label>
          <span class="weui-form-preview__value">{{baseInfo.qaname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">供应商</label>
          <span class="weui-form-preview__value">{{baseInfo.supplierName || '无'}}</span>
        </div>
        <template v-if="baseInfo.supplierName">
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">地块</label>
            <span class="weui-form-preview__value">{{baseInfo.arealandname}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">开户行</label>
            <span class="weui-form-preview__value">{{baseInfo.bank}}</span>
          </div>
          <div class="weui-form-preview__item">
            <label class="weui-form-preview__label">银行账号</label>
            <span class="weui-form-preview__value">{{baseInfo.bankcode}}</span>
          </div>
        </template>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">产品</label>
          <span class="weui-form-preview__value">{{baseInfo.productname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">规格</label>
          <span class="weui-form-preview__value">{{baseInfo.specificationname}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">单价</label>
<!--          <span v-if="baseInfo.qamaintype == 2" class="weui-form-preview__value">{{attachUnit(baseInfo.price, '元/淀粉含量*吨')}}</span>-->
          <span class="weui-form-preview__value">{{attachUnit(baseInfo.price, '元/吨')}}</span>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.harvestType == 2">
          <label class="weui-form-preview__label">采收数量</label>
          <span class="weui-form-preview__value">{{attachUnit(baseInfo.weight, '吨')}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">付款方式</label>
          <span class="weui-form-preview__value">{{baseInfo.paymentmethod == 1 ? '装车付' : '验收付'}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">扣杂方式</label>
          <span class="weui-form-preview__value">{{baseInfo.deducttypeName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">扣杂标准</label>
          <span class="weui-form-preview__value">{{baseInfo.isdiscountName}}</span>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.deducttype == 1 || baseInfo.deducttype == 3">
          <label class="weui-form-preview__label">扣杂率</label>
          <span class="weui-form-preview__value">{{attachUnit(baseInfo.discountrate, '%')}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">状态</label>
          <span class="weui-form-preview__value">{{baseInfo.statusname}}</span>
        </div>
<!--        <div class="weui-form-preview__item">-->
<!--          <label class="weui-form-preview__label">备注</label>-->
<!--          <span class="weui-form-preview__value">{{baseInfo.remark}}</span>-->
<!--        </div>-->
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">操作人</label>
          <span class="weui-form-preview__value">{{baseInfo.createName}}</span>
        </div>
        <div class="weui-form-preview__item">
          <label class="weui-form-preview__label">创建时间</label>
          <span class="weui-form-preview__value">{{baseInfo.createTime}}</span>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.supplierId && baseInfo.status == 100">
          <label class="weui-form-preview__label">拉货二维码</label>
<!--          <a :href="'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' + ticket">-->
          <a href="javascript:;" @click="$router.push({name: 'LoadQrcode2', query: {id: baseInfo.id, qatype: baseInfo.qatype, partb: baseInfo.supplierName, parta: baseInfo.parta, srname: baseInfo.srname, productname: baseInfo.productname}})">
            <span class="weui-form-preview__value"><img width="30" height="30" :src="'https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=' + ticket" /></span>
          </a>
        </div>
        <div class="weui-form-preview__item" v-if="baseInfo.files && baseInfo.files.length > 0">
          <label class="weui-form-preview__label">附件</label>
          <a v-for="(item, index) in baseInfo.files" :href="item.url">
            <span class="weui-form-preview__value">{{item.imagename}}</span>
          </a>
        </div>
      </div>
    </div>
    <!--    审批记录-->
    <SalesOperationLogs7 :orderid="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :flowid="flowid"></SalesOperationLogs7>
    <!--    </div>-->
    <!--  </div>-->
    <CommentBom v-if="isReady" :flowid="flowid" :nodeid="nodeid" :id="id" :srguid="baseInfo.srguid" :departid="baseInfo.departid" :model="baseInfo" navgateUrl="/harvest2/contract/list" ></CommentBom>
  </div>
</template>

<script>
  import SalesOperationLogs7 from '@/components/common/SalesOperationLogs7'
  import CommentBom from '@/components/common/CommentBom'

  export default {
    name: 'ViewProCtract2',
    data() {
      return {
        flowid: 39,
        userid: localStorage.userId,//'oIuV2v77MaLCAQILhjI6h6oTWpHI',
        id: '',
        baseInfo: {},
        baseItems: [],
        qaform: [],
        qaFormImg: [],
        isReady: false,
        ticket: ''
      }
    },
    components: {
      SalesOperationLogs7,
      CommentBom
    },
    created() {
      window.addEventListener('setItem', () => {
        this.openid = localStorage.getItem('openid');
        this.userid = localStorage.getItem('userId');
      })
    },
    async mounted() {
      this.id = this.$route.query.id;
      //图片浏览器
      $('.weui-panel').on('click', '.uploaderFiles .attachimg', function () {
        var num = $(this).parent().children().not(".exp").length;
        var imgArr = [];
        for (var i = 0; i < num; i++) {
          imgArr.push($(this).parent().find('.attachimg').eq(i).data('img'));
        }
        var pnum = $(this).parent().find('.exp').length;
        var index = pnum > 0 ? $(this).index() - pnum : $(this).index();
        var pb = $.photoBrowser({
          items: imgArr,
          initIndex: index
        });
        pb.open();
      });
      await this.getbaseInfo(this.id);
      this.getQrcode();
    },
    methods: {
      getQrcode: function() {
        let that = this;
        if (!that.baseInfo.supplierId) return;
        let postData = {};
        postData.contractid = this.baseInfo.id;
        that.axios({
          method: 'get',
          url: '/prod-api/harvest/procurementcontract/supplyScanCode',
          params: postData
        }).then((response) => {
          if (response.data.code == 200) {
            this.ticket = response.data.msg;
            // this.$router.push({name: 'LoadQrcode2'});
          } else if (response.data.msg) {
            this.toastText(response.data.msg);
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
          }
        }).catch(function (error) {
          that.toastError('系统错误');
        });
      },
      packUnit: function(unit, currency) {
        return unit != undefined && unit != '' ? currency == 2 ? '美元/' + unit : '元/' + unit : '';
      },
      getbaseInfo: async function (id) {
        await this.axios({
          method: 'get',
          url: `/prod-api/harvest/procurementcontract/${id}`,
        }).then(response => {
          if (response.data.code == 200) {
            let data = response.data;
            this.baseInfo = data.data || {};
            // this.baseItems = response.data.items;
          } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
            //不不设置提示
          } else {
            this.toastError('系统错误');
          }
          this.isReady = true;
        });
      },
    }
  }
</script>
